# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Stuart Cardall <developer@it-offshore.co.uk>
pkgname=shadow
pkgver=4.8.1
pkgrel=0
pkgdesc="PAM-using login and passwd utilities (usermod, useradd, ...)"
url="http://pkg-shadow.alioth.debian.org/"
arch="all"
license="BSD-3-Clause"
makedepends="linux-pam-dev"
subpackages="$pkgname-doc $pkgname-dbg $pkgname-uidmap"
source="https://github.com/shadow-maint/shadow/releases/download/$pkgver/shadow-$pkgver.tar.xz
	chpasswd.pamd
	login.pamd
	defaults.patch
	dots-in-usernames.patch
	pam-useradd.patch
	"
# secfixes:
#   4.5-r0:
#     - CVE-2017-12424
#   4.2.1-r11:
#     - CVE-2017-2616
#   4.2.1-r7:
#     - CVE-2016-6252

options="suid"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--target=$CTARGET \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-nls \
		--with-libpam \
		--without-audit \
		--without-selinux \
		--without-acl \
		--without-attr \
		--without-tcb \
		--without-nscd \
		--without-group-name-max-length
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	# Do not install these pam.d files they are broken and outdated.
	rm "$pkgdir"/etc/pam.d/*

	# install some pam.d files based on a patched useradd
	for pamf in groupadd groupdel groupmems groupmod \
		 useradd userdel usermod newusers
	do
		install -m0644 etc/pam.d/useradd \
			"$pkgdir/etc/pam.d/$pamf"
	done
	# nologin is provided by util-linux.
	rm "$pkgdir"/sbin/nologin
	rm "$pkgdir"/usr/share/man/man8/nologin.*

	# avoid conlict with coreutils-doc
	rm "$pkgdir"/usr/share/man/man1/groups.*

	# However, install our own for login.
	cp "$srcdir"/login.pamd "$pkgdir"/etc/pam.d/login

	# Also install custom pam configuration for chpasswd (see bug #10209)
	cp "$srcdir"/chpasswd.pamd "$pkgdir"/etc/pam.d/chpasswd

	# /etc/login.defs is not very useful - replace it with an *almost* blank file.
	rm "$pkgdir"/etc/login.defs
	echo "USERGROUPS_ENAB yes" > "$pkgdir"/etc/login.defs

	# Avoid conflict with man-pages.
	rm "$pkgdir"/usr/share/man/man3/getspnam.3* \
		"$pkgdir"/usr/share/man/man5/passwd.5*
}

uidmap() {
	pkgdesc="Utilities for using subordinate UIDs and GIDs"

	mkdir -p "$subpkgdir"
	cd "$subpkgdir"

	mkdir -p usr/bin
	mv "$pkgdir"/usr/bin/new*idmap usr/bin/
	chmod 4711 usr/bin/new*idmap

	# Used e.g. for unprivileged LXC containers.
	mkdir etc
	touch etc/subuid etc/subgid
}

sha512sums="780a983483d847ed3c91c82064a0fa902b6f4185225978241bc3bc03fcc3aa143975b46aee43151c6ba43efcfdb1819516b76ba7ad3d1d3c34fcc38ea42e917b  shadow-4.8.1.tar.xz
38e78aade316350dc26000b35335a778f12f5deb0f54ea23f84000ad92a683c519c7814165b5ed7e63187d11677993082d35dc6c21f7f66c6aee8e3fd4b3694b  chpasswd.pamd
46a6f83f3698e101b58b8682852da749619412f75dfa85cecad03d0847f6c3dc452d984510db7094220e4570a0565b83b0556e16198ad894a3ec84b3e513d58d  login.pamd
999eb67be2c1d6bcf752ce217ddbed868e4415d3e60676872db1b3da79b1c7d7da6b5d03335297d6358c41e7d21c32ba2df1bd6834ac4ba364b999ed7170f846  defaults.patch
745eea04c054226feba165b635dbb8570b8a04537d41e914400a4c54633c3a9cf350da0aabfec754fb8cf3e58fc1c8cf597b895506312f19469071760c11f31d  dots-in-usernames.patch
0b4587e263cb6be12fa5ae6bc3b3fc4d3696dae355bc67d085dc58c52ff96edb4d163b95db2092b8c2f3310839430cac03c7af356641b42e24ee4aa6410f5cf1  pam-useradd.patch"
